package com.naicheng.ivote.views;

import java.util.HashMap;

import org.json.JSONObject;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

import com.naicheng.ivote.R;
import com.naicheng.ivote.constant.ConstantMine;
import com.naicheng.ivote.doman.BaseResponseEntity;
import com.naicheng.ivote.doman.MyShareRes;
import com.naicheng.ivote.doman.RuleBean;
import com.naicheng.ivote.engin.BaseActivity;
import com.naicheng.ivote.parser.BaseParser;
import com.naicheng.ivote.views.MyShareActivity.mAdapter;
import com.naicheng.ivote.volley.Response.Listener;

public class MyIntegActivity extends BaseActivity {

	TextView tv_integ;
	TextView tv_rull;
	TextView tv_gift;
	TextView tv_send;
	TextView tv_back;
	RuleBean bean;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_mymsg);
		tv_integ = (TextView) this.findViewById(R.id.tv_integ);
		tv_rull = (TextView) this.findViewById(R.id.tv_rull);
		tv_gift = (TextView) this.findViewById(R.id.tv_gift);
		tv_send = (TextView) this.findViewById(R.id.tv_send);
		tv_back = (TextView) this.findViewById(R.id.tv_back);
		tv_send.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent intent = new Intent(getApplicationContext(),
						MyIntegHandsel.class);
				intent.putExtra("bean", bean);
				startActivity(intent);
			}
		});
		tv_back.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				finish();
			}
		});
	}

	@Override
	protected void onStart() {
		super.onStart();
		getData();
	}

	private void getData() {
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("userid", ConstantMine.userid);
		super.getDataFromServer("myintegral", map, new Listener<JSONObject>() {

			@Override
			public void onResponse(JSONObject response) {
				System.out.println("response------>" + response.toString());
				BaseResponseEntity<RuleBean> mResponse = new BaseParser<RuleBean>()
						.parserDomain(response, RuleBean.class);
				if (mResponse != null && mResponse.getState()) {
					bean = mResponse.getSingleDomain();
					fillPage();
				}

			}
		}, this);
	}

	private void fillPage() {
		if (bean != null) {
			tv_integ.setText(String.valueOf(bean.integral));
			tv_rull.setText(bean.rule);
			tv_gift.setText(bean.gift);
		}
	}

}
